package at.fhooe.mcm12.java.sensors;

import java.util.ArrayList;

import at.fhooe.mcm12.java.enums.SensorType;
import at.fhooe.mcm12.java.interfaces.ISensorListener;
import at.fhooe.mcm12.java.sensors.data.GPSPosition;

public class SensorController implements ISensorListener{
	
	private ArrayList<AbstractSensor<?>> m_sensors;
	
	public SensorController()
	{
		m_sensors = new ArrayList<AbstractSensor<?>>();
	}
	
	public void enableSensor(AbstractSensor<?> _sensor)
	{
		if(_sensor != null && m_sensors.contains(_sensor))
		{
			_sensor.setActive(true);
		}
	}
	
	public void disableSensor(AbstractSensor<?> _sensor)
	{
		if(_sensor != null && m_sensors.contains(_sensor))
		{
			_sensor.setActive(false);
		}
	}
	
	public void addSensor(AbstractSensor<?> _sensor)
	{
		if(_sensor != null && !m_sensors.contains(_sensor))
		{
			m_sensors.add(_sensor);
			
			if(_sensor.getSensorType() == SensorType.Push)
			{
				((PushSensor<?>)_sensor).addSensorListener(this);
			}
		}
	}
	
	public void removeSensor(AbstractSensor<?> _sensor)
	{
		if(_sensor != null && m_sensors.contains(_sensor))
		{
			m_sensors.remove(_sensor);
		}
	}

	@Override
	public void onSensorValueReceived(Object value) {
		if(value != null)
		{
			if(value instanceof GPSPosition)
			{
				System.out.println("SensorController > Position received");
			}
		}
	}
}
